﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input; 

namespace LP2
{
    class Enemy:Creature
    {
        Boolean Attacked;
        int typeCreature;
        float fAplicada;
        float angleShoot;
        float lastXBeforeColision;
        float lastYBeforeColision;
        int numberColision;
        float t;
        int dirFX;
        int dirFY;
        Boolean flagDown=false;
        Boolean onAir = false;
        Boolean flagStopped = false;




        public Enemy(CreaturePropertyConfig cpc, int typeCreature,int posx,int posy)
        {
            position = new Vector2(posx, posy);
            this.HP = cpc.getEnemyHPList()[typeCreature-1];
            this.masa = cpc.getEnemyMASAList()[typeCreature - 1];
            this.Attacked = false;
            this.typeCreature = typeCreature;
            this.position = new Vector2(posx, posy);
            this.flagStopped = false;
            this.dirFX = 1 ;
            this.dirFY = 1;
        }

        public int getDirFX()
        {
            return this.dirFX;
        }

        public void setDirFX(int f)
        {
            this.dirFX = f;
        }

        public int getDirFY()
        {
            return this.dirFY;
        }

        public void setDirFY(int f)
        {
            this.dirFX = f;
        }

        public void setFlagStopped(Boolean b)
        {
            flagStopped = b;
        }

        public Boolean getflagStopped()
        {
            return this.flagStopped;
        }

        public void setFlagDown(Boolean b)
        {
            flagDown = b;
        }

        public Boolean getFlagDowm()
        {
            return this.flagDown;
        }

        public void setNumberColision(int n)
        {
            this.numberColision = n;
        }

        public void incNumberColision()
        {
            this.numberColision++;
        }

        public double getFAplicada()
        {
            return fAplicada;
        }

        public void setFAplicada(float fAplicada)
        {
            this.fAplicada=fAplicada;
        }

        public void setAttacked(Boolean Attacked)
        {
            this.Attacked = Attacked;
        }

        public Boolean getAttacked()
        {
            return this.Attacked;
        }

        public void LoadContent(ContentManager Content)
        {
            imagen = Content.Load<Texture2D>("enemy"+typeCreature);

        }



        public void setOnAir(Boolean b)
        {
            this.onAir = b;
        }

        public Boolean getOnAir()
        {
            return this.onAir;
        }

        public void Draw(SpriteBatch spbtch)
        {   
            //if (fAplicada > 0 || onAir)
            //{
            //    fAplicada-=5;
            //    position.X++;
            //    if (flagDown) position.Y++;
            //}
            spbtch.Draw(imagen, position, Color.White);
        }

        public void MoveCuzColision(Ally a,Physic phy)
        {
            //Attacked=true;
            if (numberColision == 0)
            {
                angleShoot = 0.5f;
                this.lastXBeforeColision = this.position.X;
                this.lastYBeforeColision = this.position.Y;
            }

            if ((numberColision == 1))
            {
                t = 0f;
                angleShoot = phy.CalculusAngle(this.position.Y, lastYBeforeColision,
                                                this.position.X, lastXBeforeColision);
                this.position.X = lastXBeforeColision;
                this.position.Y = lastYBeforeColision;
                numberColision++;
            }

            this.position = phy.MoveParabolico(angleShoot, t, this.position.X, this.position.Y, fAplicada* dirFX * 0.05f , fAplicada* dirFX * 0.05f);
            t += 0.03f;
        }

        public void ReduceHP(double hitAlly)
        {
            this.fAplicada = Convert.ToSingle(hitAlly/2);
            this.HP -= Convert.ToInt32(hitAlly);
        }

        public void RotateCuzColision()
        {


        }

        public Boolean IsDie()
        {
            if (this.HP <= 0) return true;
            return false;
        }

    }
}
